package com.example.interview.reflect00.t21_diy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Maint21 {
    public static void main(String[] args) {
        try {
            Class clazz = Class.forName("com.example.interview.reflect00.t21_diy.Student");
            Constructor con = clazz.getConstructor(null);
            Student s1=(Student)clazz.newInstance();
            Student s2 = (Student)con.newInstance();
            System.out.println("-1-->"+ s1);
            System.out.println("-2-->"+ s2);
            System.out.println("-3-->" + (s1==s2));//false 创建的对象当然不是相等的
            //参照：https://blog.csdn.net/sinat_38259539/article/details/71799078 图解 去理解
            System.out.println("-4-->" + (s1.getClass()==s2.getClass()));//true 对象的字节码文件只有一个！
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
